package com.uzhie.jt808.jt1078.entity;

import com.uzhie.jt808.JT808MsgBody;
import com.uzhie.jt808.msg.entity.BitConverter;
import com.uzhie.jt808.msg.entity.MyBuffer;

/**
 * 监控控制指令
 * Created by lilongfei on 2018/7/25.
 */
public class JT_9102 implements JT808MsgBody {

    //逻辑通道号
    private byte channel;
    //关闭命令的类型
    private byte orderType;
    //控制指令类型
    private byte control;
    //码流
    private byte stream;

    public JT_9102(int channel,int order,int control,int stream){
        this.setChannel(channel);
        this.setOrderType(order);
        this.setControl(control);
        this.setStream(stream);
    }

    public byte getChannel() {
        return channel;
    }

    public void setChannel(byte channel) {
        this.channel = channel;
    }

    public void setChannel(int channel) {
        byte[] channels = BitConverter.GetBytes(channel);
        setChannel(channels[3]);
    }

    public byte getOrderType() {
        return orderType;
    }

    public void setOrderType(byte orderType) {
        this.orderType = orderType;
    }

    public void setOrderType(int orderType) {
        byte[] types = BitConverter.GetBytes(orderType);
        setOrderType(types[3]);
    }

    public byte getControl() {
        return control;
    }

    public void setControl(byte control) {
        this.control = control;
    }

    public void setControl(int control) {
        byte[] controls = BitConverter.GetBytes(control);
        setControl(controls[3]);
    }

    public byte getStream() {
        return stream;
    }

    public void setStream(byte stream) {
        this.stream = stream;
    }

    public void setStream(int stream) {
        byte[] streams = BitConverter.GetBytes(stream);
        setStream(streams[3]);
    }

    @Override
    public byte[] WriteToBytes() {
        MyBuffer buffer = new MyBuffer();
        buffer.put(channel);
        buffer.put(orderType);
        buffer.put(control);
        buffer.put(stream);
        return buffer.array();
    }

    @Override
    public void ReadFromBytes(byte[] body) {
        MyBuffer buffer = new MyBuffer(body);
        setChannel(buffer.get());
        setOrderType(buffer.get());
        setControl(buffer.get());
        setStream(buffer.get());

    }

}
